/**
 * 微信修改表单
 */
import React, { Component } from 'react';
import { Button, Row, Col, Input, Form, Select } from 'antd';

const FormItem = Form.Item;

export class WxForm extends Component {
	getFieldDecorator = (id, ops = {}) => {
		const { form: { getFieldDecorator } } = this.props;
		return getFieldDecorator(id, { ...ops, getValueFromEvent: this.getValueFromEvent });
	}

	getValueFromEvent(e) {
		let value = e;
		if (!e || !e.target) {
			value = e;
		} else {
			const { target } = e;
			value = target.type === 'checkbox' ? target.checked : target.value;
		}
		if (typeof value === 'string') {
			value = value.replace(/(^\s*)|(\s*$)/g, '');
		}
		return value;
	}

	render() {
		const { data } = this.props;
		const { getFieldDecorator } = this;
		return (
			<Row gutter={16}>
				<Col span={8}><FormItem label="微信验证:" hasFeedback>
					{getFieldDecorator('wxToken', {
						initialValue: data.wxToken
					})(<Input placeholder="请输入微信验证" />)}
				</FormItem></Col>
				<Col span={8}><FormItem label="微信ID" hasFeedback>
					{getFieldDecorator('wxId', {
						initialValue: data.wxId
					})(<Input placeholder="请输入微信ID" />)}
				</FormItem></Col>
				<Col span={8}><FormItem label="微信appid" hasFeedback>
					{getFieldDecorator('wxAppid', {
						initialValue: data.wxAppid
					})(<Input placeholder="请输入微信appid" />)}
				</FormItem></Col>
				<Col span={8}><FormItem label="微信appsecret" hasFeedback>
					{getFieldDecorator('wxAppSecret', {
						initialValue: data.wxAppSecret
					})(<Input placeholder="请输入微信appsecret" />)}
				</FormItem></Col>
				<Col span={8}><FormItem label="关注推送消息" hasFeedback>
					{getFieldDecorator('wxSubscribeMsg', {
						initialValue: data.wxSubscribeMsg
					})(<Input placeholder="请输入关注推送消息" />)}
				</FormItem></Col>
				<Col span={8}><FormItem label="微信支付商户号" hasFeedback>
					{getFieldDecorator('wxParenterId', {
						initialValue: data.wxParenterId
					})(<Input placeholder="请输入微信支付商户号" />)}
				</FormItem></Col>
				<Col span={8}><FormItem label="微信支付商户key" hasFeedback>
					{getFieldDecorator('wxPartnerSecret', {
						initialValue: data.wxPartnerSecret
					})(<Input placeholder="请输入微信支付商户key" />)}
				</FormItem></Col>
				<Col span={8}><FormItem label="微信支付消息体" hasFeedback>
					{getFieldDecorator('wxPayBody', {
						initialValue: data.wxPayBody
					})(<Input placeholder="请输入微信支付消息体" />)}
				</FormItem></Col>
			</Row>
		);
	}
}

export default Form.create()(WxForm);
